/*
* This software is licensed under the GNU General Public License, version 2
* You may copy, distribute and modify the software as long as you track changes/dates of in source files and keep all modifications under GPL. You can distribute your application using a GPL library commercially, but you must also provide the source code.

* DNNspot Software (http://www.dnnspot.com)
* Copyright (C) 2013 Atriage Software LLC
* Authors: Kevin Southworth, Matthew Hall, Ryan Doom

* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

* Full license viewable here: http://www.gnu.org/licenses/gpl-2.0.txt
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DNNspot.LiveChat.DataModel
{
    public class SessionInfo
    {
        public AgentInfo Agent { get; set; }
        public ClientInfo Client { get; set; }

        public int? AgentId { get; set; }
        public int? CategoryId { get; set; }
        public int? ClientId { get; set; }
        public DateTime? CreatedDate { get; set; }
        public bool? IsActive { get; set; }
        public DateTime? ModifiedDate { get; set; }
        public string Notes { get; set; }
        public int? PortalId { get; set; }
        public string Question { get; set; }
        public int? SessionId { get; set; }
        public string UrlReferrer { get; set; }

        public string CategoryName
        {
            get
            {
                var retVal = string.Empty;

                if (CategoryId != null)
                {
                    var category = new Category();
                    category.LoadByPrimaryKey(Convert.ToInt32(CategoryId));

                    retVal = category.Name;
                }

                return retVal;
            }
        }

        public SessionInfo(Session session)
        {
            AgentId = session.AgentId;
            CategoryId = session.CategoryId;
            ClientId = session.ClientId;
            CreatedDate = session.CreatedDate;
            IsActive = session.IsActive;
            ModifiedDate = session.ModifiedDate;
            Notes = session.Notes;
            PortalId = session.PortalId;
            Question = session.Question;
            SessionId = session.SessionId;
            UrlReferrer = session.UrlReferrer;

            Agent = new AgentInfo();
            Client = new ClientInfo();

            if (session.AgentId != null)
            {
                var agent = new Agent();
                agent.LoadByPrimaryKey(Convert.ToInt32(session.AgentId));

                Agent = new AgentInfo(agent);
            }

            if(session.ClientId != null)
            {
                var client = new Client();
                client.LoadByPrimaryKey(Convert.ToInt32(session.ClientId));

                Client = new ClientInfo(client);
            }
        }
    }
}
